import matplotlib.pyplot as plt

class Visualizer:
    def __init__(self, data):
        self.data = data

    def plot_cumulative_returns(self):
        # 绘制累计收益率曲线
        cumulative_returns = (1 + self.data['strategy_returns']).cumprod()
        plt.figure(figsize=(10, 6))
        plt.plot(cumulative_returns)
        plt.title('Cumulative Returns')
        plt.xlabel('Date')
        plt.ylabel('Cumulative Returns')
        plt.show()

    def show_chart(self, data):
        plt.close('all')
        # 绘制股票价格和移动平均线
        plt.figure(figsize=(10, 6))
        plt.plot(data['close'], label='close Price')
        plt.plot(data['short_mavg'], label='Short Moving Average')
        plt.plot(data['long_mavg'], label='Long Moving Average')
        plt.title('Stock Price and Moving Averages')
        plt.xlabel('Date')
        plt.ylabel('Price')
        plt.legend()
        plt.show()

        # 绘制策略的累计收益率
        plt.figure(figsize=(10, 6))
        plt.plot(data['cumulative_returns'], label='Strategy Cumulative Returns')
        plt.title('Strategy Cumulative Returns')
        plt.xlabel('Date')
        plt.ylabel('Cumulative Returns')
        plt.legend()
        plt.show()
